#ifndef MAINDIALOG_H
#define MAINDIALOG_H

#include <BGeometry>
#include <BCamera>
#include <BScene>
#include <BLight>
#include <BImage>
#include <BFile>
#include <BRoundHandler>

#include <BViewer>
#include <BComboBox>
#include <BProgressBar>
#include <BDialog>
#include <BButton>
#include <BSpacer>
#include <BFileDialog>
#include <BProgressBar>
#include <BCheckBox>
#include <BRealSpinBox>

#include <BTerrain>
#include "ConvertHandler.h"

using namespace BWE;

class ConvertDialog : public BDialog
{
public:
	static BTerrain* CreateTerrain(const BString& fileName);

public:
	ConvertDialog(BWidget* parent = 0);
	~ConvertDialog();

	void setSampleSize(const BSize& size);
	const BSize& sampleSize() const;

	const BSpace& space() const;
	BImage* image() const;

protected:
	void createScene();
	void createViewer();
	void updateScene();

	BTerrain* loadTIF(const BString& fileName);
	BTerrain* loadGRD(const BString& fileName);

protected:
	void slotShowAreaClicked();
	void slotShowPointsClicked();
	void slotShowTerrainClicked();
	void slotSwapYZClicked();
	void slotStateChanged();
	void slotSizeEdited();
	void slotOptimizedClicked();

	void slotAreaAdjusted();
	void slotResetButtonClicked();
	void slotOpenButtonClicked();
	void slotOrthoButtonClicked();
	void slotExtractButtonClicked();

	void slotOrthoCameraFramed(BObject* object, const BValue& value);

protected:
	virtual void updateEvent(const BEvent& event);
	virtual void resizeEvent(const BEvent& event);
	virtual void paintEvent(const BEvent& event);

private:
	BViewer*			_viewer;
	BSpacer*			_imageSpacer;
	BSpacer*			_elevationSpacer;

	BCheckBox*			_showAreaCheckBox;
	BCheckBox*			_showPointsCheckBox;
	BCheckBox*			_showTerrainCheckBox;
	BCheckBox*			_swapYZCheckBox;
	BCheckBox*			_optimizedCheckBox;
	BRealSpinBox*		_widthSpinBox;
	BRealSpinBox*		_heightSpinBox;
	BComboBox*			_stateComboBox;

	BProgressBar*		_progressBar;
	BButton*			_openButton;
	BButton*			_resetButton;
	BButton*			_orthoButton;
	BButton*			_extractButton;
	
	ConvertHandler*			_handler;
	BCameraHolder			_camera;
	BSceneHolder			_scene;
	BLightHolder			_light;
	BNodeHolder				_node;
	BGeometryHolder			_pointsGeometry;
	BCameraHolder			_orthoCamera;
	BImageHolder			_orthoImage;
	BImageHolder			_elevationImage;

	BRealTable			_elevation;
	BShortTable				_counter;
	BSpace					_orthoArea;
	BSize					_sampleSize;
	int						_scanRow;
};

#endif